/**
 * @name ProjectName
 * @description Define global variables and functions
 * @version 1.0
 */
var Orange = (function($, window, undefined) {
    var privateVar = 1;
    var detectIE8 = navigator.appName.indexOf("Internet Explorer");
    var isIE8 = navigator.appVersion.indexOf("MSIE 8");

    function addClassDetectDocMode(){
      if(detectIE8 !==-1 && isIE8 !==-1){
        $('html').addClass('ie'+ document.documentMode +'-mod');
      }
    }

    function adjustWandC() {
        $('#container').css({
            'min-height': $(window).height()
        });
    }
    return {
        adjustWandC: adjustWandC,
        addClassDetectDocMode: addClassDetectDocMode
    };
})(jQuery, window);

$(document).ready(function() {
    Orange.adjustWandC();
    Orange.addClassDetectDocMode();
    $(window).bind('resize', function() {
        Orange.adjustWandC();
    });
});
/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'accordionOrange';

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var plugin = this,
      that = plugin.element;
      that.options = plugin.options;
      that.handler = that.find(that.options.handler);
      that.content = that.find(that.options.content);
      that.handler.each(function(idx){
        var waitingAnimation = false;
        if($(this).hasClass('active')){
          that.content.eq(idx).show();
        }
        else{
          that.content.eq(idx).hide();
        }
        $(this).bind('click.accordion', function(e){
          e.preventDefault();
          if($(e.target).hasClass('email-link')){
            location.href= $(e.target).attr('href');
            return false;
          }
          if(waitingAnimation){
            return;
          }
          waitingAnimation = true;
          if($(this).hasClass('active')){
            that.content.eq(idx).slideUp(that.options.duration, function(){
              waitingAnimation = false;
              if($.isFunction(that.options.afterAccordion)){
                that.options.afterAccordion(that);
              }
            });
            $(this).removeClass('active');//.find('.btn-add').attr('title', '+').text('+');
          }
          else{
            that.content.eq(idx).stop().slideDown(that.options.duration, function(){
              waitingAnimation = false;
              if($.isFunction(that.options.afterAccordion)){
                that.options.afterAccordion(that);
              }
            });
            $(this).addClass('active');//.find('.btn-add').attr('title', '-').text('-');
          }
        });
      });
    },
    publicMethod: function(params) {

    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    handler: 'div.accordion-header',
    content: 'div.accordion-content',
    duration: 700,
    afterAccordion: function(){}
  };

  $(function($) {
    $('.accordion').accordionOrange({
      afterAccordion: function(that){
        // if(!window.navigator.msPointerEnabled){
        //   if($('.list-sidebar').length){
        //     $('.list-sidebar').jScrollPane('refresh');
        //     $('.list-sidebar').find('.jspPane').width($('.list-sidebar').find('.jspContainer').width() - 7);
        //   }
        //   if($('.form-1').not('#form-Besoin').children('div.content').length){
        //     that.closest('.form-1').not('#form-Besoin').children('div.content').jScrollPane('refresh');
        //     // $('.form-1').not('#form-Besoin').children('div.content').jScrollPane('refresh');
        //   }
        //   if($('#form-Besoin').length){
        //     that.closest('#form-Besoin').jScrollPane('refresh');
        //     // $('#form-Besoin').jScrollPane('refresh');
        //   }
        //   if($('.tabs-content').length){
        //     that.closest('.tabs-content').children('.inner').jScrollPane('refresh');
        //     // $('.tabs-content > .inner').jScrollPane('refresh');
        //   }
        //   if($('.tab-sub-content').length){
        //     that.closest('.tab-sub-content').children('.inner').jScrollPane('refresh');
        //     // $('.tab-sub-content > .inner').jScrollPane('refresh');
        //   }
        // }
      }
    });
  });

}(jQuery, window));

/** smCustomRadio **/
(function($, window, undefined) {
	var pluginName = 'smCustomRadio';
	var privateVar = null;
	var privateMethod = function() {

	};

	function Plugin(element, options) {
		this.element = $(element);
		this.options = $.extend({}, $.fn[pluginName].defaults, options);
		this.init();
	}
	
	Plugin.prototype = {
		init: function() {
			var plugin = this,
				that = plugin.element,
				button = that.parent();
			button.each(function(){
				($(this).hasClass(plugin.options.checkedClass)) ? ($(this).children('input:radio').attr('checked','checked')) : ($(this).children('input:radio').removeAttr('checked'));
			});
			$.isFunction(plugin.options.init) && plugin.options.init.apply(that, arguments);
			button.unbind('click.customRadio').bind('click.customRadio', function(){
				if(!$(this).hasClass(plugin.options.checkedClass)){
					var name = $(this).children('input:radio').attr('name'),
						collection = $('input:radio').filter('[name="' + name + '"]'),
						current = $();
					collection.each(function(){
						if($(this).parent().hasClass(plugin.options.checkedClass)){
							current = $(this).parent();
						}
					});
					current.children('input:radio').removeAttr('checked');
					current.removeClass(plugin.options.checkedClass);
					$(this).children('input:radio').attr('checked', 'checked');
					$(this).addClass(plugin.options.checkedClass);
				$.isFunction(plugin.options.afterTicked) && plugin.options.afterTicked.call(that);	
				}
			});
		}
	};

	$.fn[pluginName] = function(options, params) {
		return this.each(function() {
			var instance = $.data(this, pluginName);
			if (!instance) {
				$.data(this, pluginName, new Plugin(this, options));
			} else if (instance[options]) {
				instance[options](params);
			} else {
				console.warn(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
			}
		});
	};

	$.fn[pluginName].defaults = {
		checkedClass: 'rdBoxTypeChecked',
		init: function(){},
		afterTicked: function(){}
	};
  
  $(function($) {
    $(':radio').smCustomRadio({
      checkedClass: 'checked'
    });
  });
}(jQuery, window));
/** smCustomCheckbox **/
(function($, window, undefined) {
	var pluginName = 'smCustomCheckbox';
	var privateVar = null;
	var privateMethod = function() {

	};

	function Plugin(element, options) {
		this.element = $(element);
		this.options = $.extend({}, $.fn[pluginName].defaults, options);
		this.init();
	}
	
	Plugin.prototype = {
		init: function() {
			var plugin = this,
				that = plugin.element,
				button = that.parent();
			that.is( ':checked' ) ? button.addClass(plugin.options.checkedClass) : button.removeClass( plugin.options.checkedClass );
			$.isFunction(plugin.options.init) && plugin.options.init.apply(that, arguments);
			button.unbind('click.ticked').bind('click.ticked', function() {
				if (button.hasClass(plugin.options.checkedClass)) {
					button.removeClass( plugin.options.checkedClass );
					that.removeAttr( 'checked' );
					//that.val('0');
				} else {
					button.addClass( plugin.options.checkedClass );
					that.attr( 'checked', 'checked' );
					//that.val('1');
				}
				$.isFunction(plugin.options.afterTicked) && plugin.options.afterTicked.call(that);
			});
		}
	};

	$.fn[pluginName] = function(options, params) {
		return this.each(function() {
			var instance = $.data(this, pluginName);
			if (!instance) {
				$.data(this, pluginName, new Plugin(this, options));
			} else if (instance[options]) {
				instance[options](params);
			} else {
				console.warn(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
			}
		});
	};

	$.fn[pluginName].defaults = {
		checkedClass: 'chkBoxTypeChecked',
		init: function(){},
		afterTicked: function(){}
	};
  
  $(function($) {
    $(':checkbox').smCustomCheckbox({
      checkedClass: 'checked'
    });
  });
}(jQuery, window));

/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'datePicker';
  var privateVar = null;
  var privateMethod = function() {

  };

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {

    },
    publicMethod: function(params) {

    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    option: 'value'
  };

  $(function($) {
    if($('#datepicker' ).length){
      var urlImage = 'images/date-picker.png';
      if($('[name="calendarIcon"]').length){
        urlImage = $('[name="calendarIcon"]').val();
      }
      $('#datepicker').datepicker({
        showOn: 'button',
        buttonImage: urlImage,
        buttonImageOnly: true,
        dateFormat: 'dd/mm/yy',
        buttonText: L10n.buttonText
      }).bind('focus.showPicker', function(){
        $(this).datepicker('show');
      });
    }
  });

}(jQuery, window));

/**
 * @name defaultSelect
 **/
(function($, window, undefined) {
	var pluginName = 'defaultSelect';
	
	function Plugin(element, options) {
		this.element = $(element);
		this.options = $.extend({}, $.fn[pluginName].defaults, options);
		this.init();
	}

	
	Plugin.prototype = {
		init: function() {
			var plugin = this,
			that = plugin.element;
			that.options = plugin.options;
			that.wrapper = that.closest(that.options.wrapper);
			that.textCustom = that.wrapper.find(that.options.textCustom);
			that.valueContainer = that.wrapper.find(that.options.valueContainer);
			that.valueContainer.val(that.find('option:selected').val());
			that.textCustom.val(that.find('option:selected').text());
			
      if('ontouchstart' in window){
        that.bind('change.changeTestCustom touchstart.changeTestCustom', function(){
          if(that.options.isInput){
            that.textCustom.val($(this).find('option:selected').text());
          }
          else{
            that.textCustom.text($(this).find('option:selected').text());
          }
          $.isFunction(that.options.afterSelect) && that.options.afterSelect.call(that, $(this).find('option:selected'));
        });
      }
      else{
        that.bind('click.changeTestCustom', function(){
          if(that.options.isInput){
            that.textCustom.val($(this).find('option:selected').text());
          }
          else{
            that.textCustom.text($(this).find('option:selected').text());
          }
          // $.isFunction(that.options.afterSelect) && that.options.afterSelect.call(that, $(this).find('option:selected'));
        });
        that.bind('change.changeTestCustom', function(){
          if(that.options.isInput){
            that.textCustom.val($(this).find('option:selected').text());
          }
          else{
            that.textCustom.text($(this).find('option:selected').text());
          }
          $.isFunction(that.options.afterSelect) && that.options.afterSelect.call(that, $(this).find('option:selected'));
        });
      }
		},
		refresh: function(){
			var plugin = this,
			that = plugin.element;
			that.options = plugin.options;
			if(that.options.isInput){
				that.textCustom.val($(this).find('option:selected').text());
			}
			else{
				that.textCustom.text($(this).find('option:selected').text());
			}
			that.valueContainer.val(that.find('option:selected').val());
		}
	};

	$.fn[pluginName] = function(options, params) {
		return this.each(function() {
			var instance = $.data(this, pluginName);
			if (!instance) {
				$.data(this, pluginName, new Plugin(this, options));
			} else if (instance[options]) {
				instance[options](params);
			} else {
				alert(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
			}
		});
	};

	$.fn[pluginName].defaults = {
		wrapper: '.select-action',
		textCustom: '.account-status',
		isInput: true,
		valueContainer: 'input.valueContainer',
		afterSelect: function(){}
	};
  
  $(function($) {
		$('select').not('#select-date-id').defaultSelect({
			wrapper: 'div.select-wrap',
      textCustom: 'span.text-select',
      isInput: false
		});
    $('#select-date-id').defaultSelect({
			wrapper: 'div.select-wrap',
      textCustom: 'span.text-select',
      isInput: false,
      afterSelect: function(t){
        //$('#get-old-diagnosis')[0].submit();
        if(t.val() !==''){
          window.location.href = $('#diag-url').val() + '/diagId/' + t.val();
        }
      }
		});
  });
}(jQuery, window));
/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
(function($, window, undefined) {
    var pluginName = 'fullBackgroundSideBar';

    function Plugin(element, options) {
        this.element = $(element);
        this.options = $.extend({}, $.fn[pluginName].defaults, options);
        this.init();
    }

    Plugin.prototype = {
        init: function() {
            var plugin = this,
                that = plugin.element,
                image = that.find('img.background-sidebar'),
                sidebarHeight = that.height(),
                sidebarWidth = that.width();
            if(image.length){
              var img = new Image();
              img.onload = function(){
                var imgWidth = this.width,
                    imgHeight = this.height;
                if(imgHeight < sidebarHeight){
                  var resultWidth = sidebarHeight / imgHeight * imgWidth;
                  var resultLeft = (resultWidth - sidebarWidth) / 2;
                  image.css({
                    'height': sidebarHeight,
                    'width': resultWidth,
                    'left': - resultLeft
                  });
                }
              };
              img.src = image.attr('src');
            }
        },
        publicMethod: function(params) {

        },
        destroy: function() {
            $.removeData(this.element[0], pluginName);
        }
    };

    $.fn[pluginName] = function(options, params) {
        return this.each(function() {
            var instance = $.data(this, pluginName);
            if (!instance) {
                $.data(this, pluginName, new Plugin(this, options));
            } else if (instance[options]) {
                instance[options](params);
            } else {
                window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
            }
        });
    };

    $.fn[pluginName].defaults = {
    };

    $(function($) {
        $('#sidebar, #sidebar2').fullBackgroundSideBar();
    });

}(jQuery, window));

/**
 * @name smLayer
 * @description jQuery plugin for showing and hidding layer.
 **/
;(function($, window, undefined) {
  var pluginName = 'smLayer';
  var document = window.document;
  var win = $(window);
  var namespace = 0;

  function Plugin(element, options) {
    var that = this;
    that.element = $(element);
    that.options = $.extend({}, $.fn[pluginName].defaults, options);
    that.init();
  }

  Plugin.prototype = {
    init: function() {
      namespace++;
      var that = this;
      that.isShow = false;
      that.forceWait = false;

      that.overlay = $('<div class="overlay"></div>').appendTo(document.body).css({
        // display: 'none',
        // backgroundColor: 'black',
        // opacity: 0,
        zIndex: that.options.zIndex
        // width: '100%',
        // height: '100%',
        // position: 'fixed',
        // top: 0,
        // left: 0
      });
      
      if('ontouchstart' in window){
        that.overlay.css({
          width: $(document.body).width(),
          height: $(document.body).height(),
          position: 'absolute',
          top: 0,
          left: 0
        });
      }

      that.layer = that.element.add(that.overlay);

      that.options.duration = that.options.animate ? that.options.duration : 0;

      that.element.css({
        display: 'none',
        opacity: 0,
        position: 'absolute',
        zIndex: that.options.zIndex + 1
      });

      if(that.options.autoshow){
        that.show();
      }
      $(that.options.btnShow).unbind('click.' + pluginName).bind('click.' + pluginName, function(e){
        e.preventDefault();
        !that.forceWait && that.show();
      });
      $(that.options.btnHide, that.element).unbind('click.' + pluginName).bind('click.' + pluginName, function(e){
        e.preventDefault();
        !that.forceWait && that.hide();
      });
      that.overlay.unbind('click.' + pluginName).bind('click.' + pluginName, function(e){
        e.preventDefault();
        !that.forceWait && that.hide();
      });

      win.unbind('resize.' + pluginName + namespace).bind('resize.' + pluginName + namespace, function(){
        that.isShow && that.rePosition();
      });
    },
    rePosition: function(){
      var that = this,
        windowWidth = win.width(),
        windowHeight = win.height(),
        layerWidth = that.element.outerWidth(),
        layerHeight = that.element.outerHeight(),
        scrollTop = win.scrollTop(),
        scrollLeft = win.scrollLeft(),
        layerPosition = 'fixed',
        layerLeft = windowWidth/2 - layerWidth/2,
        layerTop = windowHeight/2 - layerHeight/2;
      if(layerLeft < 0) {
        layerLeft = 0 + scrollLeft;
        layerPosition = 'absolute';
      }
      if(layerTop < 0) {
        layerTop = 0 + scrollTop;
        layerPosition = 'absolute';
      }
      if('ontouchstart' in window){
        that.element.css({
          display: 'block',
          position: 'absolute',
          left: layerLeft,
          top: layerTop
        });
      }
      else{
        that.element.css({
          display: 'block',
          position: layerPosition,
          left: layerLeft,
          top: layerTop
        });
      }
    },
    show: function(overlayOpacity){
      var that = this;
      that.forceWait = true;
      that.rePosition();
      that.overlay.css({
        display: 'block'
      });
      that.isShow = true;

      var opacity = overlayOpacity !== undefined ? overlayOpacity : that.options.opacity;

      that.overlay.animate({
        opacity: opacity
      }, that.options.duration);
      that.element.animate({
        opacity: 1
      }, that.options.duration, function(){
        that.forceWait = false;
        $.isFunction(that.options.afterShow) && that.options.afterShow.call(that.element);
      });
      if(that.options.autohide){
        setTimeout(function(){
          that.hide();
        }, that.options.hideDuration);
      }
    },
    hide: function(){
      var that = this;
      that.forceWait = true;
      that.layer.animate({
        opacity: 0
      }, that.options.duration, function(){
        that.layer.css({
          display: 'none'
        });
        that.isShow = false;
        that.forceWait = false;
      });
    },
    destroy: function() {
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        console.warn(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    animate: true,
    duration: 400,
    zIndex: 100,
    opacity: 0.5,
    btnShow: '',
    btnHide: '',
    autoshow: false,
    autohide: false,
    hideDuration: 4000,
    afterShow: function(){}
  };

  $(function($) {
    var btnAddMore = $('.control-sidebar .add-btn');
    var layerAddUser = $('.ajouter-popin');
    var inputUserName = $('#name-ajouter');
    var btnSubmit = $('.btn-ajouter');
    var errorText = layerAddUser.find('.error');
    if(btnAddMore.length){
      layerAddUser.smLayer({
        animate: true,
        duration: 500,
        btnShow: '.control-sidebar .add-btn',
        btnHide: 'a.icon-close'
      });

      btnAddMore.bind('click.getUserList', function(e){
        e.preventDefault();
        $.ajax({
          type: 'post',
          data: {
            csrf_token: $('[name="csrf_token"]').val(),
            mid: $('[name="mid"]').val()
          },
          url: $('[name="urlGetUser"]').val(),
          success: function(re){
            var res = $.parseJSON(re);
            var arrName = [];
            for(var i = 0, l = res.length; i < l; i++){
              arrName.push(res[i].user_name);
            }
            inputUserName.autocomplete({
              source: arrName,
              minLength: 3,
              appendTo: '.ajouter-popin .name-member'
            });
            
            function getUserID(userName){
              for(var i = 0, l = res.length; i < l; i++){
                if(arrName[i] === userName) {
                  return res[i].user_id;
                }
              }
              return -1;
            }
            
            btnSubmit.unbind('click.submitform').bind('click.submitform', function(e){
              e.preventDefault();
              errorText.hide();
              var user_id = getUserID($.trim(inputUserName.val()));
                $.ajax({
                  type: 'post',
                  url: $('[name="urlAddUser"]').val(),
                  data: {
                    csrf_token: $('[name="csrf_token"]').val(),
                    mid: $('[name="mid"]').val(),
                    uid: user_id
                  },
                  success: function(res){
                    res = $.parseJSON(res);
                    if (res.status === 404) {
                      errorText.text(res.message).show();
                    } else {
                      window.location.href = res.url;
                    }
                  },
                  error: function(){
                    errorText.text('Can not connect to server. Please try later').show();
                  }
                });
            });
          }
        });
      });
    }
    if($('.alert-success').length){
      $('.alert-success').not('.no-auto').smLayer({
        animate: true,
        duration: 500,
        autoshow: true,
        autohide: true,
        btnHide: 'a.close'
      });
    }
  });
}(jQuery, window));
/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'plugin';
  var privateVar = null;
  var privateMethod = function() {

  };

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {

    },
    publicMethod: function(params) {

    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    option: 'value'
  };

  $(function($) {
    $('[data-' + pluginName + ']')[pluginName]();
  });

}(jQuery, window));

/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'rateOrange';

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var plugin = this,
      that = plugin.element;
      that.options = plugin.options;
      that.plusBtn = that.find(that.options.plusBtn);
      that.minusBtn = that.find(that.options.minusBtn);
      that.showNumber = that.find(that.options.showNumber);
      that.initNumber = that.options.initNumber;
      that.showNumber.text(that.initNumber);
      that.maxRate = that.options.maxRate;
      that.minRate = that.options.minRate;
      if(that.attr('data-max')){
        that.maxRate = that.attr('data-max');
      }
      if(that.attr('data-min')){
        that.minRate = that.attr('data-min');
      }
      if(that.showNumber.attr('question-value')){
        that.initNumber = Number(that.showNumber.attr('question-value'));
        that.showNumber.text(that.initNumber);
      }

      that.plusBtn.bind('click.plus', function(e){
        e.preventDefault();
        if(that.initNumber < that.maxRate){
          plugin.rate(1);
        }
      });
      that.minusBtn.bind('click.minus', function(e){
        e.preventDefault();
        if(that.initNumber > that.minRate){
          plugin.rate(-1);
        }
      });
      if($.isFunction(that.options.onInitiallize)){
        that.options.onInitiallize.call(that, that.initNumber);
      }
    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };
  
  Plugin.prototype.rate = function(dir){
    var plugin = this,
    that = plugin.element;
    that.initNumber = (that.initNumber + dir + (that.maxRate+1))%(that.maxRate+1);
    that.showNumber.text(that.initNumber);
    if($.isFunction(that.options.afterRate)){
      that.options.afterRate.call(that, that.initNumber);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    initNumber: 0,
    maxRate: 3,
    minRate: 0,
    plusBtn: '',
    minusBtn: '',
    showNumber: '',
    onInitiallize: function(){},
    afterRate: function(){}
  };

  $(function($) {
    if($('.control').length){
      var diagnosisTab = $('#diagnosis-tab');
      var tabsContent = $('section.wrap-tabs-content', diagnosisTab);
      var tabHeaderList = $('ul.tab-header > li', diagnosisTab);
      var diagnosisid = $('[name="diagnosisid"]');
      var getQList = function(list){
        var arr = [];
        list.each(function(idx){
          var key = $(this).attr('question-id');
          var obj = {};
          obj[key] = $(this).find('span.number-1').text();
          arr.push(obj);
        });
        return arr;
      };
      if(tabsContent.length){
        tabsContent.each(function(idx){
          var self = $(this);
          var control = $('.control', self);
          var total = 0;
          var showTotal = $('.result span.number', self);
          var getTotal = function(){
            var tt = 0;
            control.each(function(){
              tt +=Number($(this).find('span.number-1').text());
            });
            return tt;
          };
          $('.result span.total', this).html('/' +control.length*3);
          control.rateOrange({
            plusBtn: 'a:eq(1)',
            minusBtn: 'a:eq(0)',
            showNumber: 'span.number-1',
            onInitiallize: function(init){
              total = getTotal();
              showTotal.html(' ' + total);
            },
            afterRate: function(init){
              total = getTotal();
              showTotal.html(' ' + total);
            }
          });
          showTotal.text(total);
          self.find('[name="btn-connect"]').bind('click.ajax', function(e){
            e.preventDefault();
            var qlist = getQList(self.find('ul.content-eval > li'));
            $.ajax({
              type: 'post',
              url: $('[name="base_url"]').val() +'manager/diagnosis/save',
              data: {
                uid: $('[name="uid"]').val(),
                catid: $('[name="catid"]').val(),
                mid: $('[name="mid"]').val(),
                subcatid: $('[name="subcatid"]').val(),
                csrf_token: $('[name="csrf_token"]').val(),
                tabid: tabHeaderList.filter('.active').attr('tab-id'),
                diagnosisid: diagnosisid.val(),
                qlist: qlist
              },
              success: function(res){
                var re = $.parseJSON(res);
                // if(re.status){
                  if(diagnosisid.val() === ''){
                    diagnosisid.val(re.diagnosisid);
                  }
                  if(tabHeaderList.filter('.active').next().length){
                    tabHeaderList.filter('.active').next().trigger('click.tap');
                  }
                  if(!$('.no-auto').data('smLayer')){
                    $('.no-auto').smLayer({
                      animate: true,
                      duration: 500,
                      autoshow: true,
                      autohide: true,
                      btnHide: 'a.close'
                    }).find('.content').text(re.message);
                  }
                  else{
                    $('.no-auto').smLayer('show').find('.content').text(re.message);
                  }
                // }
              },
              error: function(){
                if(!$('.no-auto').data('smLayer')){
                    $('.no-auto').smLayer({
                      animate: true,
                      duration: 500,
                      autoshow: true,
                      autohide: true,
                      btnHide: 'a.close'
                    }).find('.content').text(re.message);
                  }
                  else{
                    $('.no-auto').smLayer('show').find('.content').text(re.message);
                  }
              }
            });
          });
        });
      }
    }
  });

}(jQuery, window));

/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */


(function($, window, undefined) {
    var pluginName = 'scroll';

    function Plugin(element, options) {
        this.element = $(element);
        this.options = $.extend({}, $.fn[pluginName].defaults, options);
        this.init();
    }

    Plugin.prototype = {
        init: function() {

        },
        destroy: function() {
            $.removeData(this.element[0], pluginName);
        }
    };

    $.fn[pluginName] = function(options, params) {
        return this.each(function() {
            var instance = $.data(this, pluginName);
            if (!instance) {
                $.data(this, pluginName, new Plugin(this, options));
            } else if (instance[options]) {
                instance[options](params);
            } else {
                window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
            }
        });
    };
    $.fn[pluginName].defaults = {
        option: 'value'
    };
    
    $(function($) {
      // if(!window.navigator.msPointerEnabled){
      //   if($('.list-sidebar').length){
      //     $('.list-sidebar').jScrollPane({
      //         mouseWheelSpeed: 20,
      //         verticalGutter: 0
      //     });
      //   }
      //   if($('.form-1').not('#form-Besoin').children('div.content').length){
      //     $('.form-1').not('#form-Besoin').children('div.content').jScrollPane({
      //         mouseWheelSpeed: 20,
      //         verticalGutter: 0
      //     });
      //   }
      //   if($('#form-Besoin').length){
      //     $('#form-Besoin').children('div.content').jScrollPane({
      //       mouseWheelSpeed: 20,
      //       verticalGutter: 0
      //     });
      //   }
      //   if($('.tabs-content').length){
      //     $('.tabs-content > .inner').jScrollPane({
      //       mouseWheelSpeed: 20,
      //       verticalGutter: 0
      //     });
      //   }
      //   if($('.tab-sub-content').length){
      //     $('.tab-sub-content > .inner').jScrollPane({
      //       mouseWheelSpeed: 20,
      //       verticalGutter: 0
      //     });
      //   }
      //   $(window).bind('resize.refreshScroll', function(){
      //     if($('.tab-sub-content').length){
      //       $('.tab-sub-content > .inner').filter(':visible').jScrollPane('refresh');
      //     }
      //     if($('.list-sidebar').length){
      //       $('.list-sidebar').jScrollPane('refresh');
      //       $('.list-sidebar').find('.jspPane').width($('.list-sidebar').find('.jspContainer').width() - 7);
      //     }
      //     if($('.tabs-content').length){
      //       $('.tabs-content > .inner').filter(':visible').jScrollPane('refresh');
      //     }
      //     if($('#form-Besoin').length){
      //       $('#form-Besoin').children('div.content').filter(':visible').jScrollPane('refresh');
      //     }
      //   }).triggerEvent('resize.refreshScroll');
      // }else{
      //   $('.tab-sub-content > .inner').css('overflow', 'auto');
      // }
    });
}(jQuery, window));

/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'showRateOrange';
  var privateVar = null;
  var privateMethod = function() {

  };

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var plugin = this,
      that = plugin.element;
      that.options = plugin.options;
      that.total = that.find(that.options.total);
      that.rate = that.find(that.options.rate);
      that.wrapperStick = that.find(that.options.wrapperStick);
      that.rateStick = that.wrapperStick.find(that.options.rateStick);
      that.widOfWrapperStick = that.wrapperStick.width();
      if(Number(that.rate.text()) > 0){
        that.rateStick.animate({
          width: (Number(that.rate.text())*that.widOfWrapperStick)/Number(that.total.text())
        });
      }
      else{
        that.rateStick.animate({
          width: 0
        });
      }
    },
    refresh: function(){
      var plugin = this,
      that = plugin.element;
      that.widOfWrapperStick = that.wrapperStick.width();
      if(Number(that.rate.text()) > 0){
        that.rateStick.animate({
          width: (Number(that.rate.text())*that.widOfWrapperStick)/Number(that.total.text())
        });
      }
      else{
        that.rateStick.animate({
          width: 0
        });
      }
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    wrapperStick:'div.show-rate',
    rateStick: 'span',
    total: 'div.rate .tumber-type-all',
    rate: 'div.rate .number-type-1'
  };

  $(function($) {
    if($('.wrap-rate').length){
      $('.wrap-rate').showRateOrange();
    }
  });

}(jQuery, window));

/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'slideBarOrange';

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var plugin = this,
      that = plugin.element;
      that.options = plugin.options;
      that.list = that.find(that.options.list);

      that.list.each(function(idx){
        var self = $(this);
        self.bind('click.showItem', function(){
          //if(!self.hasClass(that.options.activeClass)){
            //that.list.removeClass(that.options.activeClass);
            //self.addClass(that.options.activeClass).index();
          //}
          window.location.href = $(this).find('a.name-people').attr('href');
        });
        self.find(that.options.deleteBtn).bind('click.showItem', function(e){
          e.preventDefault();
          e.stopPropagation();
          // self.remove();
          if($.isFunction(that.options.afterDelete)){
            that.options.afterDelete.call(that, self);
          }
        });
      });
    },
    publicMethod: function(params) {

    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    list: 'ul.list-info >li',
    deleteBtn: 'a.icon-delete',
    afterDelete: function(){},
    activeClass: 'active'
  };

  $(function($) {
    if($('.list-sidebar').length){
      var listSidebar = $('.list-sidebar');
      var list = listSidebar.find('ul.list-info >li');
      var getUid = $('[name="uid"]', listSidebar);
      var getMid = $('[name="mid"]', listSidebar);
      var cct = $("input[name=csrf_token]").val();
      var removeBtn = $('.control-sidebar .remove-btn');
      var deleteUser = function(mid, uid, callback){
        var confirmV = confirm(L10n.confirm.user);
        var Url = 'manager/index/archive';
        if($('[name="iaArchiveUser"]').length){
          Url = $('[name="iaArchiveUser"]').val();
        }
        if(confirmV){
          $.ajax({
            type: 'post',
            url: $('[name="base_url"]').val() + Url,
            data: {
              mid: mid,
              uid: uid,
              csrf_token: cct
            },
            success: function(res){
              var resp = $.parseJSON(res);
              if(resp.status){
                window.location.href = resp.url;
              }
            }
          });
          if(callback){
            callback();
          }
        }
      };
      if(getUid.length){
        list.each(function(){
          if($(this).attr('ia-id') === getUid.val()){
            list.removeClass('active');
            $(this).addClass('active');
          }
        });
        // if(!list.filter('.active').length){
          // list.eq(0).addClass('active');
        // }
      }
      else{
        list.removeClass('active');
        list.eq(0).addClass('active');
      }
      if(removeBtn.length){
        removeBtn.bind('click.ajaxRemove', function(e){
          e.preventDefault();
          deleteUser(getMid.val(), getUid.val());
        });
      }
      listSidebar.slideBarOrange({
        afterDelete: function(self){
          deleteUser(self.attr('manager-id'), self.attr('ia-id'), function(){
            self.remove();
          });
        }
      });
    }
  });

}(jQuery, window));

/**
 *  @name plugin
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {
  var pluginName = 'tabOrange';

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var plugin = this,
      that = plugin.element;
      that.options = plugin.options;
      that.trigger = that.find(that.options.trigger);
      that.content = that.find(that.options.content);
      that.subtabContent = that.find(that.options.subtabContent);
      
      that.trigger.each(function(idx){
        if(!$(this).hasClass('active')){
          that.content.eq(idx).hide();
          if(that.options.subtab){
            that.subtabContent.eq(idx).hide();
          }
        }
        $(this).bind('click.tap', function(e){
          e.preventDefault();
          that.trigger.removeClass('active');
          $(this).addClass('active');
          that.content.hide().eq(idx).show();
          if(that.options.subtab){
            that.subtabContent.hide().eq(idx).show();
          }
          if($.isFunction(that.options.afterClick)){
            that.options.afterClick.call(that);
          }
        });
      });
    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    trigger: '',
    content: '',
    subtab: false,
    subtabContent: '',
    afterClick: function(){}
  };

  $(function($) {
    if($('#diagnosis-tab').length){
      $('#diagnosis-tab').tabOrange({
        trigger: 'ul.tab-header > li',
        content: 'section.wrap-tabs-content'
      });
    }
    if($('#overview-tab').length){
      var overviewTab = $('#overview-tab');
      var diagnosisid = $('[name="diagnosisid"]', overviewTab);
      var tabHeaderList = $('ul.tab-header > li', overviewTab);
      if($('.tab-sub').length){
        var tabSub = $('.tab-sub', overviewTab);
        var tabSubContent = $('section.tabs-content', overviewTab);
        tabSub.each(function(idx){
          var self = $(this);
          tabSubContent.eq(idx).find('.tab-sub-content').hide().eq(0).show();
          self.find('li').each(function(idx2){
            self.find('li').eq(0).addClass('active');
            $(this).bind('click.tap', function(e){
              e.preventDefault();
              self.find('li').removeClass('active');
              $(this).addClass('active');
              tabSubContent.eq(idx).find('.tab-sub-content').hide().eq(idx2).show();
              if($('.wrap-rate').length){
                $('.wrap-rate').showRateOrange('refresh');
              }
            });
          });
        });
      }
      overviewTab.tabOrange({
        trigger: 'ul.tab-header > li',
        content: 'section.wrap-tabs-content > section.tabs-content',
        afterClick: function(){
          if($('.wrap-rate').length){
            $('.wrap-rate').showRateOrange('refresh');
          }
        }
      });
      
      overviewTab.find('section.wrap-tabs-content > section.tabs-content').each(function(){
        var self = $(this);
        self.find('[name="btn-save"]').bind('click.doAjax', function(e){
          e.preventDefault();
          var catID = overviewTab.find('.tab-header > li.active').attr('cat-id');
          var activeSubtab;
          $('.tab-sub-content').filter('[cat-id="' + catID + '"]').each(function(){
            if($(this).css('display') === 'block'){
              activeSubtab = $(this);
            }
          });
          $.ajax({
            type: 'post',
            url: $('[name="base_url"]').val() + 'manager/overview/save',
            data: {
              uid: $('[name="uid"]', overviewTab).val(),
              mid: $('[name="mid"]', overviewTab).val(),
              diagnosisid: diagnosisid.val(),
              catid: catID,
              subcatid: activeSubtab.attr('sub-cat-id'),
              csrf_token: overviewTab.prev().find('[name="csrf_token"]').val(),
              seller_action: $('[name="seller_action"]', activeSubtab).val(),
              ia_action: $('[name="ia_action"]', activeSubtab).val(),
              training: $('[name="training"]', activeSubtab).val(),
              other_support: $('[name="other_support"]', activeSubtab).val(),
              affaire: $('[name="affaire"]', activeSubtab).val()
            },
            success: function(re){
              var res = $.parseJSON(re);
              if(res.status){
                if(diagnosisid.val() === ''){
                  diagnosisid.val(res.diagnosisid);
                }
                if(!$('.no-auto').data('smLayer')){
                    $('.no-auto').smLayer({
                      animate: true,
                      duration: 500,
                      autoshow: true,
                      autohide: true,
                      btnHide: 'a.close'
                    }).find('.content').text(res.message);
                  }
                  else{
                    $('.no-auto').smLayer('show').find('.content').text(res.message);
                  }
                // if(tabHeaderList.filter('.active').next().length){
                //   tabHeaderList.filter('.active').next().trigger('click.tap');
                // }
              }
            },
            error: function(){
              // if(!$('.no-auto').data('smLayer')){
                // $('.no-auto').smLayer({
                  // animate: true,
                  // duration: 500,
                  // autoshow: true,
                  // autohide: true,
                  // btnHide: 'a.close'
                // }).find('.content').text(res.message);
              // }
              // else{
                // $('.no-auto').smLayer('show').find('.content').text(res.message);
              // }
            }
          });
        });
      });
    }
  });

}(jQuery, window));


/**
 *  @name popupEmail
 *  @description description
 *  @version 1.0
 *  @options
 *    option
 *  @events
 *    event
 *  @methods
 *    init
 *    publicMethod
 *    destroy
 */
;(function($, window, undefined) {

  var pluginName = 'popupEmail',
      sendMailForm = $('#send-mail-form'),
      buttonSendMail = null,
      buttonClose = null,
      overlay = null,
      alertSuccess = null,
      alertContent = null,
      body = $(document.body),
      emailMessage = $('#email-message'),
      buttonCloseAlert = null,
      windowOpen = $(window);

  function Plugin(element, options) {
    this.element = $(element);
    this.options = $.extend({}, $.fn[pluginName].defaults, options);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var that = this;
      that.originContent = emailMessage.val();
      that.element.unbind('click.'+ pluginName).bind('click.'+ pluginName, function(e){
        e.preventDefault();
        buttonSendMail = sendMailForm.find('.btn-send-mail');
        buttonClose = sendMailForm.find('.icon-close-email');
        that.show(this,buttonSendMail,buttonClose);
      });
    },
    show: function(that,buttonSendMail,buttonClose) {
      var self = this;
      $(body).append('<div id="overlay"></div>');
      var insertContent = $(that).closest('.accordion').find('#seller_action').val(),
          insertContent = insertContent.replace(/\n/g, '<br />'),
          fullContent = self.originContent.replace('[email_message]', insertContent);

      alertSuccess = $('.alert-success'),
      alertContent = alertSuccess.find('.content'),
      buttonCloseAlert = alertSuccess.find('.close');

      emailMessage.val(fullContent);
      $('#email-from').val('');
      $('#email-to').val('');
      sendMailForm.css({
        'opacity' : 1
      }).fadeIn();

      overlay = $('#overlay');

      overlay.css({
        'opacity': 0.5,
        'display': 'block',
        'position': 'fixed',
        'width': '100%',
        'height': '100%',
        'z-index': 9,
        'background-color': '#000',
        'top' : 0,
        'left': 0
      });
      buttonSendMail.unbind('click.'+ pluginName).bind('click.'+ pluginName, function(e){
        e.preventDefault();
        Plugin.prototype.sendMail(this);
      });
      buttonClose.unbind('click.'+ pluginName).bind('click.'+ pluginName, function(e){
        e.preventDefault();
        Plugin.prototype.hide();
      });
      overlay.unbind('click.'+ pluginName).bind('click.'+ pluginName, function(e){
        e.preventDefault();
        buttonCloseAlert.click();
        Plugin.prototype.hide();
      });
      

    },
    sendMail: function(that) {
      var ajaxUrl = '/manager/overview/sendEmail';
      $.ajax({
          url: ajaxUrl,
          timeout: 15000,
          type: "POST",
          data: {
            csrf_token : $('[name="csrf_token"]').val(),
            emailfrom : $('#email-from').val(),
            emailto : $('#email-to').val(),
            message : $('#email-message').val()
          },
		  crossDomain: true,
          success: function(data){
            if(data != '' && data != null && data != undefined){
              dataContent = JSON.parse(data);
              if(dataContent.status){
                Plugin.prototype.hide();
              }
              else{
                $(alertContent).text(dataContent.message);
                var newLeft = (windowOpen.width() - alertSuccess.outerWidth())/2,
                    newTop = (windowOpen.height() - alertSuccess.outerHeight())/2;
                $(alertSuccess).css({
                  'top': newTop,
                  'left': newLeft
                }).fadeIn();
                $(sendMailForm).fadeOut();
                buttonCloseAlert.unbind('click.'+ pluginName).bind('click.'+ pluginName, function(e){
                  e.preventDefault();
                  Plugin.prototype.hideAlert();
                });
              }
            }
          }
      });
      return false;
    },
    hide: function() {
      sendMailForm.fadeOut(function(){
        overlay.css({
          'display':'none'
        });
      });
    },
    hideAlert: function() {
      alertSuccess.fadeOut(function(){
        overlay.css({
          'display':'none'
        });
      });
    },
    resize: function(that) {
      var newLeft = (windowOpen.width() - that.outerWidth())/2,
          newTop = (windowOpen.height() - that.outerHeight())/2;
          $(that).css({
            'top': newTop,
            'left': newLeft
          });
    },
    destroy: function() {
      $.removeData(this.element[0], pluginName);
    }
  };

  $.fn[pluginName] = function(options, params) {
    return this.each(function() {
      var instance = $.data(this, pluginName);
      if (!instance) {
        $.data(this, pluginName, new Plugin(this, options));
      } else if (instance[options]) {
        instance[options](params);
      } else {
        window.console && console.log(options ? options + ' method is not exists in ' + pluginName : pluginName + ' plugin has been initialized');
      }
    });
  };

  $.fn[pluginName].defaults = {
    option: 'value'
  };

  $(function($) {
    $('.email-link')[pluginName]();
    windowOpen.resize(function(){
      Plugin.prototype.resize(alertSuccess);
      Plugin.prototype.resize(sendMailForm);
    });
  });

}(jQuery, window));

